package com.turtle3d.visualizator;

import javax.media.j3d.Shape3D;
import javax.vecmath.Matrix4f;
import javax.vecmath.Point3f;

import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;

public class MyLeaf extends Shape3D {

	public MyLeaf(float size){
		
		Point3f vertex[] = new Point3f[4];
		
		vertex[0] = new Point3f(0,0,0);
		vertex[1] = new Point3f(-0.3f,0.5f,0);
		vertex[2] = new Point3f(0,1f,0);
		vertex[3] = new Point3f(+0.3f,0.5f,0);						
				
		//per polygon
		Point3f points[] = new Point3f[8];
		points[0] = vertex[0];
		points[1] = vertex[1];
		points[2] = vertex[2];
		points[3] = vertex[3];
		
		points[4] = vertex[3];
		points[5] = vertex[2];
		points[6] = vertex[1];
		points[7] = vertex[0];
              
		int[] stripCounts = new int[2];
		stripCounts[0] = 4;
		stripCounts[1] = 4;			
		
		int[] contourCount = new int[2];
		for(int i=0;i<2;i++)
			contourCount[i] = 1;	
		
		Matrix4f scale = new Matrix4f();
		scale.setIdentity();
		scale.setScale(size);
		for(Point3f p:vertex)
			scale.transform(p);
		
		
		GeometryInfo gInf = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);

		gInf.setCoordinates(points);
		gInf.setStripCounts(stripCounts);
		gInf.setContourCounts(contourCount);
		
		NormalGenerator ng = new NormalGenerator();
		ng.setCreaseAngle((float) Math.toRadians(45));
		ng.generateNormals(gInf);
		this.setGeometry(gInf.getGeometryArray());
     
		
	
		
	}
	
}
